const path = require("path");
// 引入插件
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  entry: "./src/index.js",
  mode: "development",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",
  },
  module: {
    rules: [
      {
        // js文件使用babel-loader来处理
        test: /\.?js$/,
        exclude: /(node_modules)/,
        use: {
          loader: "babel-loader",
        },
      },
      // css和less文件按less-loader、css-loader、style-loader的顺序处理，即写在后面的先处理
      {
        test: [/\.css$/, /\.less$/],
        use: [
          {
            loader: "style-loader",
            options: {
              // insert: "body",
            },
          },
          {
            loader: "css-loader",
            options: {
              modules: false,
            },
          },
          { loader: "sass-loader" },
        ],
      },
      // 图片资源使用url-loader处理
      {
        test: /\.(png|jpe?g|gif|svg)$/,
        loader: "url-loader",
        options: {
          // limit: 10000
        },
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./public/index.html",
      filename: "index.html",
      title: "MD",
    }),
  ],
  devServer: {
    static: "./dist",
    host: "localhost",
    port: 8089,
  },
};
